const http=require('../../utils/http')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        cateList:[],
        page:1,
        cateid:0,
        time:[]
    },
    methods:{
        setTime(t){
            let m = parseInt(t/60)
            let s = parseInt(t%60)
            m=m<10?"0"+m:m
            s=s<10?"0"+s:s
            return m+"'"+s+"'"
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // console.log(options.cateid);
        let time = []
        http.get('/post/getPostInCate?p=1&size=10&cateid='+this.data.cateid).then(res=>{
            // console.log(res);
        //    for(let i = 0;i<res.length;i++){
        //         time.push(this.methods.setTime(res[i].duration))
        //    } 
            this.setData({
                cateList:res,
                cateid:options.cateid,
                // time:time
            })
        })
    },

    onReachBottom: function (options) {
        let p = this.data.page
        p++
        this.setData({
            page:p
        })
        
        wx.showLoading({
          title: '加载中...',
        })
        // console.log(p);
        http.get(`/post/getPostInCate?p=${p}&size=10&cateid=${this.data.cateid}`).then(
           
            res=>{
                wx.hideLoading()
                // console.log(res);
                let newcatelists = res
                let oldcateposts = this.data.cateList
                let moreLists = oldcateposts.concat(newcatelists)
                // oldcateposts = moreLists
               this.setData({
                  cateList:moreLists
               })
            }
        )
    },
    onPullDownRefresh: function (options) {
        let p = this.data.page
        p++
        this.setData({
            page:p
        })
        
        wx.showLoading({
          title: '加载中...',
        })
        // console.log(p);
        http.get(`/post/getPostInCate?p=${p}&size=10&cateid=${this.data.cateid}`).then(
           
            res=>{
                wx.hideLoading()
                // console.log(res);
                let newcatelists = res
                let oldcateposts = this.data.cateList
                let moreLists = newcatelists.concat(oldcateposts)
                // oldcateposts = moreLists
               this.setData({
                  cateList:moreLists
               })
            }
        )
       
     },
})